package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.AccountLockVo;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 用户帐户api控制器
 *
 * @author ym
 * @date 2025/06/28 15:43
 */
@Tag(name = "用户账户管理")
@RestController
@RequestMapping("api/account")
@SuppressWarnings({"all"})
public class UserAccountApiController {

    @Autowired
    private UserAccountService userAccountService;

    /**
     * 获得可用金额
     *
     * @param userId 用户ID
     * @return {@link BigDecimal}
     */
    @GuiGuLogin
    @GetMapping("/userAccount/getAvailableAmount")
    public Result<BigDecimal> getAvailableAmount() {
        Long userId = AuthContextHolder.getUserId();
        BigDecimal availableAmount = userAccountService.getAvailableAmount(userId);
        return Result.ok(availableAmount);
    }

    /**
     * 检查并锁定
     *
     * @param accountLockVo 账户锁定
     * @return {@link Result}
     */
    @GuiGuLogin
    @PostMapping("/userAccount/checkAndLock")
    public Result checkAndLock(@RequestBody AccountLockVo accountLockVo) {
        Long userId = AuthContextHolder.getUserId();
        userAccountService.checkAndLock(userId, accountLockVo);
        return Result.ok();
    }
    @GuiGuLogin
    @GetMapping("/rechargeInfo/getRechargeInfo/{orderNo}")
    public Result<RechargeInfo> getRechargeInfo(@PathVariable String orderNo) {
        Long userId = AuthContextHolder.getUserId();
        RechargeInfo rechargeInfo = userAccountService.getRechargeInfo(orderNo, userId);
        return Result.ok(rechargeInfo);
    }

}

